home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270cp.lha / gnu / lib / g++-include / CursesW.h < prev    next >
C/C++ Source or Header  |  1995-07-28  |  15KB  |  609 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1989 Free Software Foundation
  5.     written by Eric Newton (newton@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #ifndef _CursesWindow_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _CursesWindow_h
  25.  
  26. #include   <_G_config.h>
  27. #if _G_HAVE_CURSES
  28. // Even many system which mostly have C++-ready header files,
  29. // do not have C++-ready curses.h.
  30. extern "C" {
  31. #include   <curses.h>
  32. }
  33.  
  34. /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
  35.    Undefine it here, because CursesWindow uses lines as a method.  */
  36. #undef lines
  37.  
  38. // "Convert" macros to inlines, if needed.
  39. #ifdef addch
  40. inline int (addch)(char ch)  { return addch(ch); }
  41. #undef addch
  42. #endif
  43. #ifdef addstr
  44. /* The (char*) cast is to hack around missing const's */
  45. inline int (addstr)(const char * str)  { return addstr((char*)str); }
  46. #undef addstr
  47. #endif
  48. #ifdef clear
  49. inline int (clear)()  { return clear(); }
  50. #undef clear
  51. #endif
  52. #ifdef clearok
  53. inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
  54. #undef clearok
  55. #else
  56. extern "C" int clearok(WINDOW*, int);
  57. #endif
  58. #ifdef clrtobot
  59. inline int (clrtobot)()  { return clrtobot(); }
  60. #undef clrtobot
  61. #endif
  62. #ifdef clrtoeol
  63. inline int (clrtoeol)()  { return clrtoeol(); }
  64. #undef clrtoeol
  65. #endif
  66. #ifdef delch
  67. inline int (delch)()  { return delch(); }
  68. #undef delch
  69. #endif
  70. #ifdef deleteln
  71. inline int (deleteln)()  { return deleteln(); }
  72. #undef deleteln
  73. #endif
  74. #ifdef erase
  75. inline int (erase)()  { return erase(); }
  76. #undef erase
  77. #endif
  78. #ifdef flushok
  79. inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
  80. #undef flushok
  81. #else
  82. #define _no_flushok
  83. #endif
  84. #ifdef getch
  85. inline int (getch)()  { return getch(); }
  86. #undef getch
  87. #endif
  88. #ifdef getstr
  89. inline int (getstr)(char *_str)  { return getstr(_str); }
  90. #undef getstr
  91. #endif
  92. #ifdef getyx
  93. inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
  94. #undef getyx
  95. #endif
  96. #ifdef inch
  97. inline int (inch)()  { return inch(); }
  98. #undef inch
  99. #endif
  100. #ifdef insch
  101. inline int (insch)(char c)  { return insch(c); }
  102. #undef insch
  103. #endif
  104. #ifdef insertln
  105. inline int (insertln)()  { return insertln(); }
  106. #undef insertln
  107. #endif
  108. #ifdef leaveok
  109. inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
  110. #undef leaveok
  111. #else
  112. extern "C" int leaveok(WINDOW* win, int bf);
  113. #endif
  114. #ifdef move
  115. inline int (move)(int x, int y)  { return move(x, y); }
  116. #undef move
  117. #endif
  118. #ifdef refresh
  119. inline int (rfresh)()  { return refresh(); }
  120. #undef refresh
  121. #endif
  122. #ifdef scrollok
  123. inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
  124. #undef scrollok
  125. #else
  126. #ifndef hpux
  127. extern "C" int scrollok(WINDOW*, int);
  128. #else
  129. extern "C" int scrollok(WINDOW*, char);
  130. #endif
  131. #endif
  132. #ifdef standend
  133. inline int (standend)()  { return (int) standend(); }
  134. #undef standend
  135. #endif
  136. #ifdef standout
  137. inline int (standout)()  { return (int) standout(); }
  138. #undef standout
  139. #endif
  140. #ifdef wstandend
  141. inline int (wstandend)(WINDOW *win)  { return wstandend(win); }
  142. #undef wstandend
  143. #endif
  144. #ifdef wstandout
  145. inline int (wstandout)(WINDOW *win)  { return wstandout(win); }
  146. #undef wstandout
  147. #endif
  148. #ifdef winch
  149. inline int (winch)(WINDOW* win) { return winch(win); }
  150. #undef winch
  151. #endif
  152.  
  153. /* deal with conflicting macros in ncurses.h  which is SYSV based*/
  154. #ifdef box
  155. inline int _G_box(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
  156. #undef box
  157. inline int box(WINDOW* win, chtype v, chtype h) {return _G_box(win, v, h); }
  158. #endif
  159. #ifdef scroll
  160. inline int (scroll)(WINDOW* win) { return scroll(win); }
  161. #undef scroll
  162. #endif
  163. #ifdef touchwin
  164. inline int (touchwin)(WINDOW* win) { return touchwin(win); }
  165. #undef touchwin
  166. #endif
  167.  
  168. #ifdef mvwaddch
  169. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  170. { return mvwaddch(win, y, x, ch); }
  171. #undef mvwaddch
  172. #endif
  173. #ifdef mvwaddstr
  174. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  175. { return mvwaddstr(win, y, x, (char*)str); }
  176. #undef mvwaddstr
  177. #endif
  178. #ifdef mvwdelch
  179. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  180. #undef mvwdelch
  181. #endif
  182. #ifdef mvwgetch
  183. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  184. #undef mvwgetch
  185. #endif
  186. #ifdef mvwgetstr
  187. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  188. {return mvwgetstr(win,y,x, str);}
  189. #undef mvwgetstr
  190. #endif
  191. #ifdef mvwinch
  192. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  193. #undef mvwinch
  194. #endif
  195. #ifdef mvwinsch
  196. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  197. { return mvwinsch(win, y, x, c); }
  198. #undef mvwinsch
  199. #endif
  200.  
  201. #ifdef mvaddch
  202. inline int (mvaddch)(int y, int x, char ch)
  203. { return mvaddch(y, x, ch); }
  204. #undef mvaddch
  205. #endif
  206. #ifdef mvaddstr
  207. inline int (mvaddstr)(int y, int x, const char * str)
  208. { return mvaddstr(y, x, (char*)str); }
  209. #undef mvaddstr
  210. #endif
  211. #ifdef mvdelch
  212. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  213. #undef mvdelch
  214. #endif
  215. #ifdef mvgetch
  216. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  217. #undef mvgetch
  218. #endif
  219. #ifdef mvgetstr
  220. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  221. #undef mvgetstr
  222. #endif
  223. #ifdef mvinch
  224. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  225. #undef mvinch
  226. #endif
  227. #ifdef mvinsch
  228. inline int (mvinsch)(int y, int x, char c)
  229. { return mvinsch(y, x, c); }
  230. #undef mvinsch
  231. #endif
  232.  
  233. /*
  234.  *
  235.  * C++ class for windows.
  236.  *
  237.  *
  238.  */
  239.  
  240. class CursesWindow 
  241. {
  242. protected:
  243.   static int     count;           // count of all active windows:
  244.                                   //   We rely on the c++ promise that
  245.                                   //   all otherwise uninitialized
  246.                                   //   static class vars are set to 0
  247.  
  248.   WINDOW *       w;               // the curses WINDOW
  249.  
  250.   int            alloced;         // true if we own the WINDOW
  251.  
  252.   CursesWindow*  par;             // parent, if subwindow
  253.   CursesWindow*  subwins;         // head of subwindows list
  254.   CursesWindow*  sib;             // next subwindow of parent
  255.  
  256.   void           kill_subwindows(); // disable all subwindows
  257.  
  258. public:
  259.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  260.  
  261.                  CursesWindow(int lines,          // number of lines
  262.                               int cols,           // number of columns
  263.                               int begin_y,        // line origin
  264.                               int begin_x);       // col origin
  265.  
  266.                  CursesWindow(CursesWindow& par,  // parent window
  267.                               int lines,          // number of lines
  268.                               int cols,           // number of columns
  269.                               int by,             // absolute or relative
  270.                               int bx,             //   origins:
  271.                               char absrel = 'a'); // if `a', by & bx are
  272.                                                   // absolute screen pos,
  273.                                                   // else if `r', they are
  274.                                                   // relative to par origin
  275.                 ~CursesWindow();
  276.  
  277. // terminal status
  278.   int            lines(); // number of lines on terminal, *not* window
  279.   int            cols();  // number of cols  on terminal, *not* window
  280.  
  281. // window status
  282.   int            height(); // number of lines in this window
  283.   int            width();  // number of cols in this window
  284.   int            begx();   // smallest x coord in window
  285.   int            begy();   // smallest y coord in window
  286.   int            maxx();   // largest  x coord in window
  287.   int            maxy();   // largest  x coord in window
  288.  
  289. // window positioning
  290.   int            move(int y, int x);
  291.  
  292. // coordinate positioning
  293.   void           getyx(int& y, int& x);
  294.   int            mvcur(int sy, int ey, int sx, int ex);
  295.  
  296. // input
  297.   int            getch();
  298.   int            getstr(char * str);
  299.   int            scanw(const char *, ...);
  300.  
  301. // input + positioning
  302.   int            mvgetch(int y, int x);
  303.   int            mvgetstr(int y, int x, char * str);
  304.   int            mvscanw(int, int, const char*, ...);
  305.  
  306. // output
  307.   int            addch(const char ch);
  308.   int            addstr(const char * str);
  309.   int            printw(const char * fmt, ...);
  310.   int            inch();
  311.   int            insch(char c);
  312.   int            insertln();
  313.  
  314. // output + positioning
  315.   int            mvaddch(int y, int x, char ch);
  316.   int            mvaddstr(int y, int x, const char * str);
  317.   int            mvprintw(int y, int x, const char * fmt, ...);
  318.   int            mvinch(int y, int x);
  319.   int            mvinsch(int y, int x, char ch);
  320.  
  321. // borders
  322.   int            box(char vert, char  hor);
  323.  
  324. // erasure
  325.   int            erase();
  326.   int            clear();
  327.   int            clearok(int bf);
  328.   int            clrtobot();
  329.   int            clrtoeol();
  330.   int            delch();
  331.   int            mvdelch(int y, int x);
  332.   int            deleteln();
  333.  
  334. // screen control
  335.   int            scroll();
  336.   int            scrollok(int bf);
  337.   int            touchwin();
  338.   int            refresh();
  339.   int            leaveok(int bf);
  340. #ifndef _no_flushok
  341.   int            flushok(int bf);
  342. #endif
  343.   int            standout();
  344.   int            standend();
  345.  
  346. // multiple window control
  347.   int            overlay(CursesWindow &win);
  348.   int            overwrite(CursesWindow &win);
  349.  
  350.  
  351. // traversal support
  352.   CursesWindow*  child();
  353.   CursesWindow*  sibling();
  354.   CursesWindow*  parent();
  355. };
  356.  
  357.  
  358. #ifdef __amigados__
  359.  
  360. /* The <curses.h> file in the ixemul environment is a port of the BSD 4.4 lite
  361.    distribution.  This one doesn't have leading underscores on some of the
  362.    __window members. */
  363.  
  364. #define _begx begx
  365. #define _begy begy
  366. #define _maxx maxx
  367. #define _maxy maxy
  368.  
  369. #endif /* __amigados__ */
  370.  
  371. inline int CursesWindow::begx()
  372. {
  373.   return w->_begx;
  374. }
  375.  
  376. inline int CursesWindow::begy()
  377. {
  378.   return w->_begy;
  379. }
  380.  
  381. inline int CursesWindow::maxx()
  382. {
  383.   return w->_maxx;
  384. }
  385.  
  386. inline int CursesWindow::maxy()
  387. {
  388.   return w->_maxy;
  389. }
  390.  
  391. inline int CursesWindow::height()
  392. {
  393.   return maxy() - begy() + 1;
  394. }
  395.  
  396. inline int CursesWindow::width()
  397. {
  398.   return maxx() - begx() + 1;
  399. }
  400.  
  401. inline int CursesWindow::box(char vert, char  hor)    
  402. {
  403.   return ::box(w, vert, hor); 
  404. }
  405.  
  406. inline int CursesWindow::overlay(CursesWindow &win)         
  407. {
  408.   return ::overlay(w, win.w); 
  409. }
  410.  
  411. inline int CursesWindow::overwrite(CursesWindow &win)       
  412. {
  413.   return ::overwrite(w, win.w); 
  414. }
  415.  
  416. inline int CursesWindow::scroll()                     
  417. {
  418.   return ::scroll(w); 
  419. }
  420.  
  421.  
  422. inline int CursesWindow::touchwin()                   
  423. {
  424.   return ::touchwin(w); 
  425. }
  426.  
  427. inline int CursesWindow::addch(const char ch)         
  428. {
  429.   return ::waddch(w, ch); 
  430. }
  431.  
  432. inline int CursesWindow::addstr(const char * str)     
  433. {
  434.   // The (char*) cast is to hack around prototypes in curses.h that
  435.   // have const missing in the parameter lists.  [E.g. SVR4]
  436.   return ::waddstr(w, (char*)str); 
  437. }
  438.  
  439. inline int CursesWindow::clear()                      
  440. {
  441.   return ::wclear(w); 
  442. }
  443.  
  444. inline int CursesWindow::clrtobot()                   
  445. {
  446.   return ::wclrtobot(w); 
  447. }
  448.  
  449. inline int CursesWindow::clrtoeol()                   
  450. {
  451.   return ::wclrtoeol(w); 
  452. }
  453.  
  454. inline int CursesWindow::delch()                      
  455. {
  456.   return ::wdelch(w); 
  457. }
  458.  
  459. inline int CursesWindow::deleteln()                   
  460. {
  461.   return ::wdeleteln(w); 
  462. }
  463.  
  464. inline int CursesWindow::erase()                      
  465. {
  466.   return ::werase(w); 
  467. }
  468.  
  469. inline int CursesWindow::getch()                      
  470. {
  471.   return ::wgetch(w); 
  472. }
  473.  
  474. inline int CursesWindow::getstr(char * str)           
  475. {
  476.   return ::wgetstr(w, str); 
  477. }
  478.  
  479. inline int CursesWindow::inch()                       
  480. {
  481.   return winch(w); 
  482. }
  483.  
  484. inline int CursesWindow::insch(char c)               
  485. {
  486.   return ::winsch(w, c); 
  487. }
  488.  
  489. inline int CursesWindow::insertln()                   
  490. {
  491.   return ::winsertln(w); 
  492. }
  493.  
  494. inline int CursesWindow::move(int y, int x)           
  495. {
  496.   return ::wmove(w, y, x); 
  497. }
  498.  
  499.  
  500. inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
  501. {
  502.   return ::mvcur(sy, ey, sx,ex);
  503. }
  504.  
  505. inline int CursesWindow::mvaddch(int y, int x, char ch)
  506. {
  507.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
  508. }
  509.  
  510. inline int CursesWindow::mvgetch(int y, int x)
  511. {
  512.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
  513. }
  514.  
  515. inline int CursesWindow::mvaddstr(int y, int x, const char * str)
  516. {
  517.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
  518. }
  519.  
  520. inline int CursesWindow::mvgetstr(int y, int x, char * str)
  521. {
  522.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
  523. }
  524.  
  525. inline int CursesWindow::mvinch(int y, int x)
  526. {
  527.   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
  528. }
  529.  
  530. inline int CursesWindow::mvdelch(int y, int x)
  531. {
  532.   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
  533. }
  534.  
  535. inline int CursesWindow::mvinsch(int y, int x, char ch)
  536. {
  537.   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
  538. }
  539.  
  540. inline int CursesWindow::refresh()                   
  541. {
  542.   return ::wrefresh(w); 
  543. }
  544.  
  545. inline int CursesWindow::clearok(int bf)             
  546. {
  547.   return ::clearok(w,bf); 
  548. }
  549.  
  550. inline int CursesWindow::leaveok(int bf)             
  551. {
  552.   return ::leaveok(w,bf); 
  553. }
  554.  
  555. inline int CursesWindow::scrollok(int bf)            
  556. {
  557.   return ::scrollok(w,bf); 
  558. }
  559.  
  560. #ifndef _no_flushok
  561. inline int CursesWindow::flushok(int bf)            
  562. {
  563.   return ::flushok(w, bf); 
  564. }
  565. #endif
  566.  
  567. inline void CursesWindow::getyx(int& y, int& x)       
  568. {
  569.   ::getyx(w, y, x); 
  570. }
  571.  
  572. inline int CursesWindow::standout()                   
  573. {
  574.   return (int) ::wstandout(w); 
  575. }
  576.  
  577. inline int CursesWindow::standend()                   
  578. {
  579.   return (int) ::wstandend(w); 
  580. }
  581.  
  582. inline int CursesWindow::lines()                      
  583. {
  584.   return LINES; 
  585. }
  586.  
  587. inline int CursesWindow::cols()                       
  588. {
  589.   return COLS; 
  590. }
  591.  
  592. inline CursesWindow* CursesWindow::child()
  593. {
  594.   return subwins;
  595. }
  596.  
  597. inline CursesWindow* CursesWindow::parent()
  598. {
  599.   return par;
  600. }
  601.  
  602. inline CursesWindow* CursesWindow::sibling()
  603. {
  604.   return sib;
  605. }
  606.  
  607. #endif /* _G_HAVE_CURSES */
  608. #endif
  609.